package rsj.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rsj.dao.PrtyDao;
import rsj.domain.ProductTypePo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ProdTypeService {
    private static final Logger logger = LoggerFactory.getLogger(ProdTypeService.class);
    private static final ProdTypeService instance = new ProdTypeService();
    public static ProdTypeService getInstance() {
        return instance;
    }

    private static final PrtyDao PRTY_DAO = PrtyDao.getInstance();

    /**
     * 获取所有一级，二级类目
     * @return
     */
    public Map<String, List<Map<String, String>>> getProductTypeAll() {
        List<ProductTypePo> oneType = PRTY_DAO.getOneType();
        List<ProductTypePo> TwoType = PRTY_DAO.getTwoType();

        Map<String, List<Map<String, String>>> typesAll = new HashMap<>();
        typesAll.put("Prod_TypeOneList", getOneTypeList(oneType));
        typesAll.put("Prod_TypeTwoList", getTwoTypeList(TwoType));

        return typesAll;
    }

    private List<Map<String, String>> getTwoTypeList(List<ProductTypePo> oneType) {
        List<Map<String, String>> vos = new ArrayList<>();

        oneType.forEach(productTypePo -> {
            Map<String, String> tables = new HashMap<>();
            tables.put("Prty_Sid", productTypePo.getPrty_Sid());
            tables.put("Prty_Sname", productTypePo.getPrty_Sname());
            vos.add(tables);
        });

        return vos;
    }

    private List<Map<String, String>> getOneTypeList(List<ProductTypePo> oneType) {
        List<Map<String, String>> vos = new ArrayList<>();

        oneType.forEach(productTypePo -> {
            Map<String, String> tables = new HashMap<>();
            tables.put("Prty_Fid", productTypePo.getPrty_Fid());
            tables.put("Prty_Fname", productTypePo.getPrty_Fname());
            vos.add(tables);
        });

        return vos;
    }
}
